const { defineConfig } = require('@vue/cli-service');
const { stringified } = require('../scripts/server/env');

const {
  VUE_APP_PORT,
} = process.env;
const publicPath = process.env.MICRO_PUBLIC_PATH;
module.exports = defineConfig({
  publicPath,
  transpileDependencies: true,
  devServer: {
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    host: '0.0.0.0',
    open: true,
    hot: true,
    port: VUE_APP_PORT || 9790,
  },
  chainWebpack(config) {
    // 添加自定义环境变量
    config.plugin('define').tap((args) => {
      args[0]['process.env'] = {
        ...args[0]['process.env'],
        ...stringified,
      };
      return args;
    });
  },
  configureWebpack: {
    resolve: {
      fallback: {
        path: require.resolve('path-browserify'),
      },
    },
    externals: {
      fs: require('fs'),
    },
  },
});
